package com.k12.admim.controller.area;

import com.k12.admim.model.entity.sys.SysAreaCities;
import com.k12.admim.model.entity.sys.SysAreaDistricts;
import com.k12.admim.model.entity.sys.SysAreaProvinces;
import com.k12.admim.rpc.EduManageFeignClient;
import com.k12.admim.rpc.UserFeignClient;
import com.k12.admim.utils.RequestContextUtil;
import com.k12.common.model.resp.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("find")
public class AreaController {

    @Resource
    private UserFeignClient userFeignClient;

    @PostMapping("/findCityList")
    public R findCityList(@RequestBody SysAreaCities sysAreaCities){
        String tenantId = RequestContextUtil.getTenantId();
        if (tenantId == null){
            return R.failed("非法登录");
        }
        List<SysAreaCities> sysAreaCitiesList = userFeignClient.findCityList(sysAreaCities);
        return R.success(sysAreaCitiesList);
    }


    @PostMapping("/findDistrictsList")
    public R findDistrictsList(@RequestBody SysAreaDistricts sysAreaDistricts){
        String tenantId = RequestContextUtil.getTenantId();
        if (tenantId == null){
            return R.failed("非法登录");
        }
        List<SysAreaDistricts> sysAreaCitiesList = userFeignClient.findDistrictsList(sysAreaDistricts);
        return R.success(sysAreaCitiesList);
    }

    @GetMapping("/findProvincesList")
    public R findProvincesList(){
        String tenantId = RequestContextUtil.getTenantId();
        if (tenantId == null){
            return R.failed("非法登录");
        }
        SysAreaProvinces sysAreaProvinces = new SysAreaProvinces();
        sysAreaProvinces.setTenantId(Long.valueOf(tenantId));
        List<SysAreaProvinces> sysAreaCitiesList = userFeignClient.findProvincesList(sysAreaProvinces);
        return R.success(sysAreaCitiesList);
    }
}
